<template xmlns:v-on="http://www.w3.org/1999/xhtml">
  <div class="content">
      <!-- 头部 -->
    <div class="main-title">
      <ul>
        <li>
          <div @click="navBackClick(1)" class="main-title-left main-title-noSelect">
            首页
          </div>
          <div class="main-title-right">
            /
          </div>
        </li>
        <li>
          <div @click="navBackClick(1)" class="main-title-left main-title-noSelect">
            简历库
          </div>
          <div class="main-title-right">
            /
          </div>
        </li>
        <li>
          <div class="main-title-left main-title-select">
            发送邀请
          </div>
          <div class="main-title-right">
            <!-- / -->
          </div>
        </li>
      </ul>
    </div>
    <div class="content-center" v-loading="loading">
      <div class="main-list">
        <div class="list-two">
          <div class="list-two-list">
            <div>姓名</div>
            <div>
             {{invitationObj.name}}
            </div>
          </div>
          <div class="list-two-list">
            <div>岗位</div>
            <div>
              {{invitationObj.position | positionFun}}          
            </div>
          </div>
        </div>
        <div class="list-two">
          <div class="list-two-list">
            <div>手机号</div>
            <div>
              {{invitationObj.phone}}    
            </div>
          </div>
          <div class="list-two-list">
            <div>邮箱</div>
            <div>
              <!-- {{invitationObj.email}} -->
              <input type="text" v-model="emailVal">               
            </div>
          </div>
        </div>
        <div class="list-two">
          <div class="list-two-list">
            <div>面试时间</div>
            <div>
               <el-date-picker format="yyyy-MM-dd HH:mm"  v-model="issueDate" type="datetime" placeholder="选择时间">
               </el-date-picker>            
            </div>
          </div>
          <div class="list-two-list">
            <div>面试官</div>
            <div>
              <input type="text" v-model="interviewerVal">                    
            </div>
          </div>
        </div>
        <div class="list-two">
          <div class="list-two-list">
            <div>通知方式</div>
            <div>
              <select @change="selectTypesClick" v-model="notifyWaytype">
                <option v-for="(type,index) in notifyWaytypes" v-bind:value="index" :key="index">{{type.name}}</option>
              </select>             
            </div>
          </div>
          <div class="list-two-list">
          </div>
        </div>
        <div class="list-button">
          <div class="button-look" v-show="updateOrLokkShow" @click="lookClick">
            预&nbsp;&nbsp;览
          </div>
          <div class="button-look-a" v-show="!updateOrLokkShow">
            <a v-if="invitationObj.file" :href="invitationObj.file">
              下&nbsp;&nbsp;载
            </a>
            <a v-else>
              无&nbsp;简&nbsp;历
            </a>
          </div>
          <div class="button-save" @click="addClick">
            保&nbsp;&nbsp;存
          </div>
          <div class="button-cancel" @click="backClick">
            取&nbsp;&nbsp;消
          </div>
        </div>
      </div>
      <!-- 预览 -->
      <div v-show="isShowLook" class="lookShow">
        <div class="main-lookShow">
          <div class="main-lookShow-top">
            <div>个人简历</div>
            <div @click="lookHideClick">X</div>
          </div>
          <div class="main-lookShow-bottom">
            <iframe :src='pdfurls' v-if="pdfurlsShow" width="100%" height="500" scrolling="no">
              您的浏览器不支持框架
            </iframe>
            <div class="main-lookShow-bottom-pdfImg" v-else>
              <img :src="pdfurls" alt="">
            </div>
          </div>
          <div class="main-lookShow-button">
            <!--  @click="upLookClick" -->
            <a class="button-lookShow-save" :href="pdfurlsHref">下载</a>
          </div>
        </div>
      </div>
      <div :class="{showdel:isShowdel}" class="delPopup">
        <transition name="slide-fade">
          <div class="delContent">
            <v-mIntercept @ok="confirmClick" @canle="cancelClick" :name="titlename"></v-mIntercept>
          </div>
        </transition>
      </div>
    </div>
  </div>
</template>
<script>
import { mapActions } from "vuex";

import mIntercept from "../module/mIntercept";
export default {
  components: {
    "v-mIntercept": mIntercept
  },
  data() {
    return {
      loading: false,
      updateOrLokkShow: false,
      pdfurlsShow: false,
      pdfurlsHref: "",
      pdfurls: "",
      isShowLook: false,
      type: "0",
      types: [{ name: "默认模板" }],
      notifyWaytype: "0",
      notifyWaytypes: [{ name: "邮件", index: 2 }],
      issueDate: "",
      isShowdel: true,
      intercept: false,
      toPath: "",
      titlename: "劳动成果还未保存，是否退出？",
      invitationObj: {},
      interviewerVal: "",
      emailVal: ""
    };
  },
  // 过滤
  filters: {
    timeFun: function(val) {
      var now = new Date(val);
      var year = now.getYear() - 100;
      var month = now.getMonth() + 1;
      month = month > 9 ? month : "0 " + month;
      var date = now.getDate();
      date = date > 9 ? date : "0 " + date;
      var hour = now.getHours();
      hour = hour > 9 ? hour : "0 " + hour;
      var minute = now.getMinutes();
      minute = minute > 9 ? minute : "0 " + minute;
      return (
        "20 " + year + "- " + month + "- " + date + " " + hour + ": " + minute
      );
    },
    positionFun: function(val) {
      if (val) {
        var self = this;
        var descStr = "";
        var descArr = JSON.parse(sessionStorage.getItem("poststr"));
        descArr.forEach(function(ele, ind) {
          if (ele.value == val) {
            descStr = ele.desc;
          }
        });
        return descStr;
      } else {
        return "无";
      }
    }
  },
  // 模块新建时
  created: function() {
    var self = this;
    self.invitationObj = JSON.parse(sessionStorage.getItem("allListObj"));
    if (self.invitationObj.email) {
      self.emailVal = self.invitationObj.email;
    }
    if (self.invitationObj.file) {
      var fileStr = self.invitationObj.file;

      fileStr = fileStr.split("file/")[1].split(".")[1];
      if (fileStr == "doc") {
        self.updateOrLokkShow = false;
      } else {
        self.updateOrLokkShow = true;
      }
    } else {
      self.updateOrLokkShow = false;
    }
  },
  // 计算属性
  mounted() {},
  // 事件处理
  methods: {
    // 预览
    lookHideClick() {
      this.isShowLook = false;
      this.isShowfeedback = false;
      this.pdfurlsShow = false;
    },
    upLookClick() {
      var self = this;
      window.open(self.invitationObj.file);
    },
    lookClick() {
      var self = this;
      if (self.invitationObj.file) {
        if (
          self.invitationObj.file.indexOf(".PNG") > -1 ||
          self.invitationObj.file.indexOf(".png") > -1 ||
          self.invitationObj.file.indexOf(".jpg") > -1
        ) {
          self.pdfurls = self.invitationObj.file;
          self.pdfurlsShow = false;
          self.isShowLook = true;
          self.updateOrLokkShow = true;
          self.pdfurlsHref = self.invitationObj.file;
        } else {
          self.pdfurlsHref = self.invitationObj.file;
          var fileStr = self.invitationObj.file;
          fileStr = fileStr.split("file/")[1];
          this.isShowLook = true;
          // urlFileName
          self
            .getuploaddocx2PdfPreviewer({
              name: fileStr
            })
            .then(data => {
              if (data.code == 200) {
                self.pdfurls =
                  "/static/PDFShow/generic/web/viewer.html?file=" +
                  data.data.src;
                this.pdfurlsShow = true;
              } else {
                self.$message({
                  type: "info",
                  message: data.message
                });
              }
            })
            .catch(msg => {
              this.$router.push({
                path: "/login"
              });
              self.$message({
                type: "info",
                message: "服务器异常!"
              });
            });
        }
      } else {
        self.$message({
          type: "info",
          message: "暂无简历，无法预览!"
        });
      }
    },
    // 面包屑返回
    navBackClick(index) {
      if (index == 2) {
        this.$router.push({
          path: "/home/resume/all"
        });
      } else if (index == 1) {
        this.$router.push({
          path: "/home/resume/all"
        });
      }
    },
    // 返回
    backClick() {
      var self = this;
      self.$router.push({
        path: "/home/resume/all"
      });
    },
    addClick() {
      var self = this;
      var vFunFalse = self.vFun();
      if (vFunFalse == true) {
        var issueDateTimeStr = new Date(self.issueDate).getTime();
        self.loading = true;
        self
          .gethumanResourcesendAppointment({
            id: self.$route.query.id,
            name: self.invitationObj.name,
            phone: self.invitationObj.phone,
            email: self.emailVal,
            source: self.invitationObj.source,
            position: self.invitationObj.position,
            notifyWay: self.notifyWaytypes[self.notifyWaytype].index,
            interviewer: self.interviewerVal,
            interviewTime: issueDateTimeStr
          })
          .then(data => {
            self.loading = false;
            if (data.code == 200) {
              self.$message({
                type: "success",
                message: "发送邮件成功!"
              });
              self.$router.push({
                path: "/home/resume/all"
              });
            } else {
              self.$message({
                type: "info",
                message: data.message
              });
            }
          })
          .catch(msg => {
            self.loading = false;
            self.$message({
              type: "info",
              message: "服务器异常!"
            });
          });
      }
    },
    vFun() {
      var self = this;
      var phoneReg = new RegExp(/^\d{11}$/);
      var numReg = new RegExp(/^\d{1,7}$/);
      var num1Reg = new RegExp(/^\d{1,7}$/);
      var emailReg = new RegExp(
        /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
      );
      var strReg = new RegExp(/^[a-zA-Z\u4e00-\u9fa5]{1,10}$/);
      var vFunFalse = false;
      if (emailReg.test(self.emailVal) == true) {
        if (self.issueDate) {
          if (strReg.test(self.interviewerVal) == true) {
            vFunFalse = true;
          } else {
            self.$message({
              type: "info",
              message: "面试官项必填且为汉字"
            });
            vFunFalse = false;
          }
        } else {
          self.$message({
            type: "info",
            message: "面试时间项必填"
          });
          vFunFalse = false;
        }
      } else {
        self.$message({
          type: "info",
          message: "邮箱项输入不正确"
        });
        vFunFalse = false;
      }

      return vFunFalse;
    },
    selectTypesClick() {},
    confirmClick() {
      this.intercept = true;
      var url = this.toPath;
      this.$router.push({
        path: url
      });
    },
    //取消未保存弹出框
    cancelClick() {
      this.isShowdel = true;
    },
    ...mapActions([
      "gethumanResourcesendAppointment",
      "getuploaddocx2PdfPreviewer"
    ])
  },
  // 监视
  watch: {}
};
</script>
<style scoped>
.button-look-a {
  margin-left: 108px;
}
.button-look {
  cursor: pointer;
  margin-left: 8px;
  width: 74px;
  height: 32px;
  border: 1px solid #ffd9d9d9;
  text-align: center;
  line-height: 32px;
  font-size: 14px;
  border-radius: 4px;
  color: rgba(0, 0, 0, 0.65);
  background-color: #fe966d;
  margin-left: 108px;
}
.button-look-a a {
  cursor: pointer;
  color: #fff;
  display: block;
  margin: 0;
  padding: 0;
  width: 74px;
  height: 32px;
  border: 1px solid #ffd9d9d9;
  text-align: center;
  line-height: 32px;
  font-size: 14px;
  border-radius: 4px;
  color: rgba(0, 0, 0, 0.65);
  background-color: #fe966d;
}
.button-save {
  margin-left: 18px;
  width: 74px;
  height: 32px;
  border-radius: 4px;
  background-color: rgba(250, 140, 22, 1);
  text-align: center;
  line-height: 32px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  color: rgba(255, 255, 255, 1);
}
.button-cancel {
  cursor: pointer;
  margin-left: 18px;
  width: 74px;
  height: 32px;
  border: 1px solid #ffd9d9d9;
  text-align: center;
  line-height: 32px;
  font-size: 14px;
  border-radius: 4px;
  background-color: #fff;
  color: rgba(0, 0, 0, 0.65);
}
.list-button {
  margin-top: 45px;
  width: 500px;
  display: flex;
}
.list-file-r-file label {
  border-radius: 4px;
  min-width: 120px;
  height: 30px;
  background-color: #2fa89e;
  display: flex;
  align-items: center;
  justify-content: space-around;
  font-size: 14px;
  color: #fff;
  cursor: pointer;
}
.list-file-r-file label img {
  width: 20px;
  height: 20px;
}
.list-file-r-file input {
  opacity: 0;
}
.list-file-r-file {
  min-width: 110px;
  height: 28px;
  margin-left: 25px;
  display: flex;
}
.list-file-r-img {
  width: 110px;
  height: 50px;
  border: 1px solid #ccc;
}
.list-file-right {
  width: 500px;
  height: 50px;
  margin-left: 15px;
  display: flex;
  align-items: center;
}
.list-file {
  display: flex;
  height: 70px;
  margin-top: 18px;
  width: 100%;
}

.list-file > div:nth-child(1) {
  width: 150px;
  font-size: 15px;
  font-weight: 600;
  color: #666;
  text-align: right;
}
.list-text {
  display: flex;
  height: 70px;
  width: 100%;
}

.list-text > div:nth-child(1) {
  width: 150px;
  font-size: 15px;
  font-weight: 600;
  color: #666;
  text-align: right;
}
.list-text > div:nth-child(2) textarea {
  width: 560px;
  resize: none;
  height: 65px;
  border: 1px solid #ccc;
  border-radius: 4px;
}
.list-text > div:nth-child(2) {
  margin-left: 15px;
  min-width: 540px;
  height: 65px;
}

.list-two-list {
  display: flex;
  width: 50%;
  align-items: center;
}
.list-two-list > div:nth-child(1) {
  width: 93px;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
  text-align: right;
}
.list-two-list > div:nth-child(2) {
  margin-left: 15px;
  width: calc(100% - 118px);
  /* border: 1px solid red; */
  color: rgba(0, 0, 0, 0.65);
  font-size: 14px;
}
.list-two-list > div:nth-child(2) input {
  width: 94%;
}
.list-two-list > div:nth-child(2) select {
  width: calc(94% + 7px);
}
.list-two > div:nth-child(2) {
  margin-left: 15px;
}

.list-two {
  display: flex;
  align-items: center;
  height: 32px;
  margin-top: 35px;
}

select {
  width: 207px;
  height: 32px;
  border-radius: 4px;
  line-height: 32px;
  color: rgba(0, 0, 0, 0.65);
  border: 1px solid #ffd7d7d7;
  padding-left: 3px;
  font-size: 14px;
}
input {
  width: 200px;
  height: 32px;
  border-radius: 4px;
  line-height: 32px;
  color: rgba(0, 0, 0, 0.65);
  border: 1px solid #ffd7d7d7;
  padding-left: 7px;
  font-size: 14px;
}
select::-ms-expand,
select::-webkit-expand {
  display: none;
}
.main-list > div {
  width: 100%;
  min-height: 32px;
}
.main-list {
  width: 100%;
  margin-top: 15px;
  min-height: 50px;
  background-color: #ffff;
  min-height: 720px;
}

.main-title-noSelect {
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
  cursor: pointer;
}
.main-title-select {
  font-size: 14px;
  color: rgba(0, 0, 0, 0.85);
  font-weight: 600;
}

.main-title-right {
  width: 23px;
  text-align: center;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
}

.main-title ul {
  width: 100%;
  display: flex;
  height: 54px;
  margin-left: 34px;
}
.main-title ul li {
  display: flex;
}
.main-title {
  width: 100%;
  height: 54px;
  background-color: #fff;
  line-height: 54px;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: inset 0px 3px 3px 0px #ccc;
}
.content {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: rgba(240, 242, 245, 1);
  min-height: 720px;
}

.content-center {
  overflow: hidden;
  width: calc(100% - 48px);
  margin-left: 24px;
  background-color: #fff;
  margin-top: 24px;
  border-radius: 3px;
  min-height: calc(100% - 78px - 24px);
  margin-bottom: 24px;
  /* border: 1px solid red; */
}

/*取消弹出框*/

.delPopup {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0);
  z-index: 1000000;
}

.showdel {
  display: none;
}

.delContent {
  width: 525px;
  height: 280px;
  background-color: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0px 10px 10px #eaeaea;
  border-radius: 7px;
  margin: calc((100vh - 280px) / 2) auto;
  z-index: 100000;
}

.slide-fade-enter-active {
  transition: all 0.7s ease;
}

.slide-fade-enter,
.slide-fade-leave-active {
  transform: translateY(-30px);
  opacity: 0;
}

.button-lookShow-save {
  width: 74px;
  height: 32px;
  border-radius: 4px;
  background-color: rgba(250, 140, 22, 1);
  text-align: center;
  line-height: 32px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  color: rgba(255, 255, 255, 1);
}

.main-lookShow-button {
  height: 55px;
  display: flex;
  width: 100%;
  margin-top: 25px;
  align-items: center;
  justify-content: center;
}

.main-lookShow-bottom .main-lookShow-bottom-pdfImg {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: scroll;
}
.main-lookShow-bottom img {
  width: 100%;
}
.main-lookShow-bottom {
  width: 90%;
  margin: 0 auto;
  margin-top: 36px;
  height: 500px;
  border: 1px solid #ccc;
}
.main-lookShow-top > div:nth-child(1) {
  font-size: 16px;
  font-weight: 600;
  color: #5c5c5c;
  margin-left: 30px;
  font-size: 20px;
  color: rgba(0, 0, 0, 1);
}

.main-lookShow-top > div:nth-child(2) {
  margin-right: 20px;
  width: 35px;
  height: 35px;
  text-align: center;
  line-height: 35px;
  border: 1px solid #ccc;
  border-radius: 50%;
  cursor: pointer;
  color: #ccc;
}

.main-lookShow-top {
  display: flex;
  justify-content: space-between;
  height: 22px;
  margin-top: 30px;
  align-items: center;
}

.main-lookShow {
  width: 900px;
  height: 700px;
  background-color: #fff;
  border-radius: 5px;
}

.lookShow {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  background-color: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>